package datahandling;

import java.util.*;
import java.util.Map.Entry;

public class Label {
	private static HashMap<Character, Integer> labelNum = new HashMap<Character,Integer>();
	private static HashMap<Character, String> labelData = new HashMap<Character, String>();

	public static void store(char c,String data,int label_pos){

		//处理数据,去掉标签
		String[] single = data.split("\\t");
		if(single[0].length() == data.length()){
			single = data.split(" ");
			if(single[0].length() == data.length())
				single = data.split(",");
		}
        List<String> list = new ArrayList<String>();  
        for (int i = 0; i<single.length; i++){  
            list.add(single[i]);  
        }  
        list.remove(label_pos);
        String outData = c + " " + list.get(0);
        for(int i = 1; i< list.size(); i++){
        		outData += " "+list.get(i);
        }
        //
		labelNum.put(c,(labelNum.get(c)==null?1:labelNum.get(c)+1));
		labelData.put(c,(labelData.get(c)==null?outData:labelData.get(c)+"\r\n"+outData));

	}
	public static void writeFile(String outPath){
        //向文件输出	
		for(Entry<Character,Integer> entry : labelNum.entrySet()){
			String fileName = "batch1_labelAt0_c"+entry.getKey()+"_"+entry.getValue();
			String data = labelData.get((entry.getKey()));
			OutPut.outTxt(outPath,fileName,data);
		}
		
	}
}
